﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.Library;
using IHISCETeim.BLL;

namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class OMailLineView : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.AddLog(Permission.查看, obj);
        }
        

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }

        protected override string DWZRef
        {
            get { return "OMailLineList"; }
        }

        protected int MLID
        {
            get
            {
                return GetRequestValue<int>("MLID", 0);
            }
        }

        protected OMailLineInfo _obj;
        protected OMailLineInfo obj
        {
            get
            {
                if (_obj == null)
                    _obj = OMailLineController.GetOMailLineById(MLID);
                return _obj;
            }
        }

        protected List<OMailLineDetailInfo> _listDetailobj;
        protected List<OMailLineDetailInfo> listDetailobj
        {
            get
            {
                if (_listDetailobj == null)
                    _listDetailobj = OMailLineController.GetOMailLineDetailByMLID(MLID);
                return _listDetailobj;
            }
        }



        protected string GetNGSelect(string controlName, string selectvalue)
        {
            string selectHtml = "";//;"<select name=\"NG_铁履H前10m\"><option value=\"OK\" selected>OK</option><option value="NG->OK">NG->OK</option><option value="NG">NG</option></select>";
            string[] ngItme = new string[] { "OK", "NG", "NG->OK", };
            foreach (string item in ngItme)
            {
                selectHtml += string.Format("<option value=\"{0}\" {1}>{0}</option>", item, item == selectvalue ? "selected" : "");
            }
            return string.Format("<select name=\"{1}\">{0}</select>", selectHtml, controlName);
        }

      
        protected string GetMainLineDetailHtml()
        {
           
            List<OMailLineDetailInfo> allGWList = listDetailobj.Distinct(new OMailLineDetailInfoDistinctComparer()).ToList();

           
            string gwItmHtmlResultItm = "";

            string hiddenMLDID = "<input type='hidden' name='MLDID' value='{0}' />";

            // string select自检结果 = GetNGSelect("SelfCheckResult");
            string input自检人 = "{0}";
            string input自检日期 = "{0}";
            //  string select抽检结果 = GetNGSelect("SamplingResult");
            string input抽检人 = "{0}";
            string input抽检日期 = "{0}";
            string input备注 = "{0}";

            foreach (OMailLineDetailInfo tempItm in allGWList)
            {

                List<OMailLineDetailInfo> gwItmList = listDetailobj.FindAll(e => e.GW == tempItm.GW);
                int rowspan = gwItmList.Count();
                string gwItmHtml = "<tr ><td >{0}</td><td >{1}</td><td >{2}</td><td >{3}</td><td >{4}</td><td >{5}</td><td >{6}</td><td >{7}</td><td >{8}</td><td >{9}{10}</td></tr>";
                string gwItmHtml2 = "<tr><td rowspan={0}>{1}</td><td  rowspan={0}>{2}</td><td >{3}</td><td >{4}</td><td >{5}</td><td >{6}</td><td >{7}</td><td >{8}</td><td >{9}</td><td >{10}</td><td >{11}</td><td >{12}{13}</td></tr>";
                int tagI = 0;

                foreach (OMailLineDetailInfo gwItm in gwItmList)
                {
                    if (tagI == 0)
                        gwItmHtmlResultItm += string.Format(gwItmHtml2, rowspan, gwItm.GW, gwItm.GWName, gwItm.ChceckInclude, gwItm.InspectionStandards, gwItm.TestMethod, gwItm.SelfCheckResult, string.Format(input自检人, gwItm.SelfCheckPeople), string.Format(input自检日期, gwItm.SelfCheckDate),  gwItm.SamplingResult, string.Format(input抽检人, gwItm.SamplingPeople), string.Format(input抽检日期, gwItm.SamplingDate), string.Format(input备注, gwItm.SamplingRemark), string.Format(hiddenMLDID, gwItm.MLDID));
                    else
                        gwItmHtmlResultItm += string.Format(gwItmHtml, gwItm.ChceckInclude, gwItm.InspectionStandards, gwItm.TestMethod, gwItm.SelfCheckResult, string.Format(input自检人, gwItm.SelfCheckPeople), string.Format(input自检日期, gwItm.SelfCheckDate), gwItm.SamplingResult, string.Format(input抽检人, gwItm.SamplingPeople), string.Format(input抽检日期, gwItm.SamplingDate), string.Format(input备注, gwItm.SamplingRemark), string.Format(hiddenMLDID, gwItm.MLDID));
                    tagI++;
                }

            }

            return gwItmHtmlResultItm;

        }
    }
}